<template>
	<view class="root" style="background-color: #FFFFFF;">
		<!-- 高龄申请 -->
		<view class="w9">
			<icon style="font-size: 30rpx; line-height: 30rpx; color: #02C9FC;" class="iconfont icon-jiekuanshenqing"></icon>
			<text style="line-height: 30rpx; font-size: 25rpx; color: #888888; display: inline-block; margin-left: 25rpx;">高龄申请</text>
		</view>
		<cross-line color="#B2B2B2" style="width: 90%;"></cross-line>
		<view class="flex" style="flex-wrap: wrap;">
			<indexModule v-for="(item,index) in gaolinList" class="module" :icon="item.icon" :url="item.url" :title="item.title"></indexModule>
		</view>
		<cross-line color="#B2B2B2" style="width: 100%;"></cross-line>

		<!-- 迁出申请 -->
		<view class="w9">
			<icon style="font-size: 30rpx; line-height: 30rpx; color: #02C9FC;" class="iconfont icon-qianchu"></icon>
			<text style="line-height: 30rpx; font-size: 25rpx; color: #888888; display: inline-block; margin-left: 25rpx;">迁出申请</text>
		</view>
		<cross-line color="#B2B2B2" style="width: 90%;"></cross-line>
		<view class="flex" style="flex-wrap: wrap;">
			<indexModule v-for="(item,index) in qianchuList" class="module" :icon="item.icon" :url="item.url" :title="item.title"></indexModule>
		</view>
		<cross-line color="#B2B2B2" style="width: 100%;"></cross-line>
		
		<!-- 核减 -->
		<view v-if="lv != 3">
			<view class="w9">
				<icon style="font-size: 30rpx; line-height: 30rpx; color: #02C9FC;" class="iconfont icon-dongtai"></icon>
				<text style="line-height: 30rpx; font-size: 25rpx; color: #888888; display: inline-block; margin-left: 25rpx;">老人动态</text>
			</view>
			<cross-line color="#B2B2B2" style="width: 90%;"></cross-line>
			<view class="flex" style="flex-wrap: wrap;">
				<indexModule v-for="(item,index) in hejianList" class="module" :icon="item.icon" :url="item.url" :title="item.title"></indexModule>
			</view>
			<cross-line color="#B2B2B2" style="width: 100%;"></cross-line>
		</view>
		
		<!-- 其他-->
		<view class="w9">
			<icon style="font-size: 30rpx; line-height: 30rpx; color: #02C9FC;" class="iconfont icon-qita"></icon>
			<text style="line-height: 30rpx; font-size: 25rpx; color: #888888; display: inline-block; margin-left: 25rpx;">其他应用</text>
		</view>
		<cross-line color="#B2B2B2" style="width: 90%;"></cross-line>
		<view class="flex" style="flex-wrap: wrap;">
			<indexModule v-for="(item,index) in roles" class="module" :icon="item.icon" :url="item.url" :title="item.title"></indexModule>
		</view>
		<cross-line color="#B2B2B2" style="width: 100%;"></cross-line>

	</view>
</template>

<script>
	import indexModule from "@/components/ui/page/application-module.vue";
	import crossLine from "@/components/ui/tg-cross-line.vue"
	export default {
		components: {
			indexModule,
			crossLine
		},
		data() {
			return {
				lv:3,
				current: 0,
				sliderX: 0,
				nickName: '',
				roles: [],
				articleList: [],
				slideList: [],
				gaolinList: [],
				qianchuList: [],
				hejianList: []
			}
		},
		async onShow() {
			var that = this
			this.nickName = uni.getStorageSync('nickName') || '请先登录';
			var token = uni.getStorageSync('token') || '';
			console.log(token)
			if (this.nickName == '请先登录') {
				uni.reLaunch({
					url: '../login/login'
				});
			}
			that.roles = []
			that.qianchuList = []
			that.hejianList = []
			that.gaolinList = []
			console.log(uni.getStorageSync('roles') || '请先登录');
			var roles = uni.getStorageSync('roles') || []
			var lv = 3;
			try {
				lv = uni.getStorageSync('info').user.roles[0].level || 3 //3表示老人
				that.lv = lv
			} catch (e) {
				lv = 3
			}
			console.log(lv)
			roles.forEach(e => {
				switch (e) {
					case "elds:subApply":
						{

							if (lv == 3) {
								console.log(e)
								that.gaolinList.push({
									title: '我要申请',
									url: '/pages/index/service/odd-age-allowance',
									weight: 1,
									icon: 'icon-zhufangbutie'
								})

							}
							break;
						}
					case "audit:list":
						{
							if (lv == 3) {
								console.log(lv)
								that.gaolinList.push({
									title: '申请记录', //老人
									url: '/pages/index/audit/record',
									weight: 2,
									icon: 'icon-jindu'
								})
							} else if (lv == 2) {
								console.log(lv)
								that.gaolinList.push({
									title: '高龄审核', //管理员
									url: '/pages/index/audit/audit',
									weight: 1,
									icon: 'icon-liebiao'
								})
							}
							break;
						}

					case "immigration:person":
						{
							console.log(e)
							that.qianchuList.push({
								title: '我要迁出',
								url: '/pages/index/emigration/emigration',
								weight: 3,
								icon: 'icon-hukouqianchubenshi'
							})
							break;
						}

					case "regulatioryplatformNotify:list":
						{

							if (lv == 3) {
								that.qianchuList.push({
									title: '迁出记录', //老人
									url: '/pages/index/outRecord/record',
									weight: 4,
									icon: 'icon-ic_history'
								})
							}
							break;
						}

					case "subsidyHistory:list":
						{
							if (lv == 3) {
								that.roles.push({
									title: '数据统计',
									url: '/pages/index/subsidyHistory/subsidyHistory',
									weight: 5,
									icon: 'icon-tongji'
								})
							}

							break;
						}


						//管理员


					case "subsidyStandard:list":
						{
							that.roles.push({
								title: '补贴历史',
								url: '/pages/index/audit/history',
								weight: 2,
								icon: 'icon-tongji'
							})
							break;
						}

					case "immigration:audit":
						{
							that.qianchuList.push({
								title: '迁出审核',
								url: '/pages/index/outRecord/outRecord',
								weight: 3,
								icon: 'icon-shenhe'
							})
							break;
						}

					case "deathInfo:list":
						{
							that.hejianList.push({
								title: '核减管理',
								url: '/pages/index/dynamic/dynamic',
								weight: 4,
								icon: 'icon-renkou'
							})
							break;
						}

				}
			})

			that.roles.sort(function(a, b) {
				return a.weight - b.weight
			})
			console.log(that.roles)


			//获取通知列表
			var articleList = await that.$api.getArticleList();
			this.articleList = articleList.data
			console.log(this.articleList.length)

			//加载轮播图
			var slideList = await that.$api.slideshow();
			console.log(slideList)
			this.slideList = slideList.data
		},
		methods: {
			subStr(begin, finish, str, ss = '') {
				if (str.length > finish) {
					return str.slice(begin, finish) + ss
				} else {
					return str
				}
			},
			//高龄动态
			toDynamic() {
				this.$utiltg.navigateTo(`/pages/index/dynamic/dynamic`);
			},
			toOutRecord() {
				this.$utiltg.navigateTo(`/pages/index/outRecord/outRecord`);
			},
			toDetail(text) {
				console.log(text)
				this.$utiltg.navigateTo(`/pages/index/detail?id=${text}`)
			},
			toSubsidyHistory() {
				if (this.nickName != '请先登录') {
					uni.navigateTo({
						url: './subsidyHistory/subsidyHistory'
					})
				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					})
				}
			},
			openOddAgeAllowance() {
				if (this.nickName != '请先登录') {
					uni.navigateTo({
						url: './service/odd-age-allowance'
					});
				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					})
				}

			},
			changePage(e) {
				this.current = e.detail.current;
			},
			changeChoice() {
				var that = this;
				if (that.sliderX == 0) {
					that.sliderX = 100;
				} else {
					that.sliderX = 0;
					that.current = 0

				}
			},
			openTask(e) {
				this.$utiltg.navigateTo('/pages/index/audit/audit')
				console.log(e)
				// uni.navigateTo({
				// 	url:'',
				// 	fail(e) {
				// 		console.log(e)
				// 	}
				// })
				// if(this.nickName != '请先登录'){
				// 	if(e == 0){

				// 	}else{

				// 	}
				// }else{
				// 	uni.showToast({
				// 		title:'请先登录',
				// 		icon:'none'
				// 	})
				// }

			},
			openProcess() {
				if (this.nickName != '请先登录') {
					uni.navigateTo({
						url: '../my/user/application-progress-detail'
					});
				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					})
				}

			},
			openApplicationRecord() {
				if (this.nickName != '请先登录') {
					uni.navigateTo({
						url: '../my/user/application-record'
					});
				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					})
				}

			},
			openAboutUs() {
				if (this.nickName != '请先登录') {
					uni.navigateTo({
						url: '../my/about-us'
					});
				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					})
				}

			},
			openFeedback() {
				if (this.nickName != '请先登录') {
					uni.navigateTo({
						url: '../my/feedback'
					});
				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					})
				}


			},
			handleMove() {
				this.$utiltg.navigateTo("/pages/index/emigration/emigration")

			}
		}
	}
</script>

<style>
	.icon-title-detail {
		font-size: 23rpx;
		color: #404040;
		text-shadow: 10rpx 10rpx 10rpx #CAEBFF;
	}

	.icon-my-detail {
		color: #4DBAFF;
		text-shadow: 10rpx 10rpx 10rpx #CAEBFF;
		font-size: 100rpx !important;
		display: block;
		margin-bottom: 15rpx;
		margin-top: 15rpx;
	}

	.icon-my {
		color: #4DBAFF;
		font-size: 100rpx !important;
		display: block;
		margin-bottom: 15rpx;
		margin-top: 50rpx;
	}

	.simple-module {
		text-align: center;
		margin: 15rpx auto;
		width: 300rpx;
		height: 300rpx;
		background-image: linear-gradient(#A4D9F9, #CAEBFF, #A4D9F9);
		border-radius: 15rpx;
		box-shadow: 10rpx 10rpx 10rpx #CCCCCC;
	}

	.is-choice {
		color: #FFFFFF !important;
	}

	.slider {

		transition: transform 0.3s;
		z-index: 125;
		width: 100rpx;
		height: 80rpx;
		border-radius: 40rpx;
		background-color: #02C9FC;
		position: absolute;
	}

	.choice {
		font-size: 25rpx;
		z-index: 150;
		text-align: center;
		width: 100rpx;
		font-weight: 400;
		line-height: 80rpx;
	}

	.article::after {
		content: '';
		height: 20rpx;
		width: 750rpx;
		display: block;
	}

	.root::before {
		content: '';
		height: 20rpx;
		width: 750rpx;
		display: block;
	}

	.no-choice {
		height: 250rpx !important;
		margin-top: 25rpx;
	}

	.banner-img {
		box-shadow: 5rpx 5rpx 5rpx #D9D9D9;
		transition: height 0.8s;
		margin-left: 15rpx;
		width: 470rpx;
		height: 295rpx;
		border-radius: 10rpx;
	}
</style>
